package com.itboye.ihomebank.myzhujia;

import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.LeiXingAdapter02;
import com.itboye.ihomebank.adapter.QuBean;
import com.itboye.ihomebank.adapter.WeiXiuDiZhiAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.QuYuBean;
import com.itboye.ihomebank.bean.QuYuBean.Children;
import com.itboye.ihomebank.bean.AvatarBeans;
import com.itboye.ihomebank.bean.AvatarDataBeans;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.WeiXiuDiZhiBean;
import com.itboye.ihomebank.bean.WeixiuXinxiBean;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.XGridView;
import com.itboye.ihomebank.custom.datepicker.wheelview.adapter.CityChildrenWheelAdapter;
import com.itboye.ihomebank.custom.datepicker.wheelview.adapter.CityWheelAdapter;
import com.itboye.ihomebank.custom.datepicker.wheelview.adapter.XiaoQuChildWheelAdapter;
import com.itboye.ihomebank.custom.datepicker.wheelview.adapter.XiaoQuFatherWheelAdapter;
import com.itboye.ihomebank.photo.CopyOfPhotoActivity;
import com.itboye.ihomebank.photo.CopyOfTestPicActivity;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.RepairPersenter;
import com.itboye.ihomebank.uploadmultipleimage.MultipartRequest;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.ChengShiPopupWindow;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.XImageLoader;
import com.itboye.ihomebank.util.XiaoQuPopupWindow;
import com.itboye.ihomebank.web.UploadImage.OnUploadlistener;
import com.itboye.ihomebank.wheelview.OnWheelScrollListener;
import com.itboye.ihomebank.wheelview.WheelView;

/**
 * 居家维修（填写内容）
 * 
 */
public class ActivityJvJiaRepair extends BaseOtherActivity implements Observer,
		OnUploadlistener {
	TextView add_shap_title_tv;
	ImageView close_icon;
	ImageView jvjia_repair_img;// 添加图片
	TextView jvjia_repair_ok;// 下一步
	/** 姓名,电话,地址,描述 */
	EditText et_name, et_phone, et_xiangqing;
	/** 选择市区,选择小区,报修类型,报修程度，详细地址 */
	RelativeLayout jvjia_repair_shiqu, jvjia_repair_xiqoqu,
			jvjia_repair_leixing, jvjia_repair_chengdu,jvjia_repair_dizhi;
	/** 市区,小区,报修类型,报修程度 */
	TextView text_shiqu, text_xiaoqu, text_leixing, text_chengdu;
	
	TextView text_dizhi;

	RepairPersenter repairPersenter;
	/** 查看维修信息(用来返回报修类型) */
	List<WeixiuXinxiBean.Furniture> household = new ArrayList<WeixiuXinxiBean.Furniture>();

	PopupWindow mPopWin;
	private RelativeLayout realLayout;
	private ListView cheng_listView;
	/** 弹出框在这个布局的下面 */
	LinearLayout shaixuan_main;

	LeiXingAdapter02 leiXingAdapter;
	/** 报修项目ID */
	String repair_id;

	/** 报修程度ID */
	int repair_status;

	List<Map<String, Object>> list;

	private ChengShiPopupWindow chengshiPop;
	private WheelView chengshiFather;
	private WheelView chengshiChild;
	List<QuYuBean> chengShiBean;// 城市
	private CityWheelAdapter nume01;
	private CityChildrenWheelAdapter cityChildAdpter;
	List<QuYuBean.Children> chengShiChildrenbean;

	HousePresenter hourse;

	private XiaoQuPopupWindow xiaoquPop;
	private WheelView xiaoquFather;
	private XiaoQuFatherWheelAdapter xiaoquFatherAdapter;
	List<QuBean> quBean;
	private XiaoQuChildWheelAdapter xiaoquChildAdapter;
	private WheelView xiaoquChild;

	/** 小区 */
	List<QuBean.Children> quBeanChildren;
	/** 小区的code */
	private String xiaoquCode;
	/** 区的code */
	private String quCode;

	/** 获取市的各个区下面的分支 */
	HousePresenter hourse02;

	RepairPersenter repairPersenter02;

	private XGridView noScrollgridview;
	private GridAdapter adapter;

	/** 存图片的ID */
	private StringBuffer sb;

	String str = null;
	private String uid;
	private String name;
	private String phone;
	private String addr;//详细地址
	protected int repairType;

	public static List<String> listImg = new ArrayList<>();
	
	//维修地址
	List<WeiXiuDiZhiBean> dizhiBean;
	WeiXiuDiZhiAdapter weiXiuDiZhiAdapter;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.jvjia_repair_dizhi:// 详细地址
			dizhiPopup(v);
		
			break;
		case R.id.jvjia_repair_shiqu:// 选择市区
			chengShi();
			chengshiPop.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.jvjia_repair_xiqoqu:// 选择小区,
			if (quBean != null) {
				xiaoqu();
				xiaoquPop.showAtLocation(v, Gravity.BOTTOM
						| Gravity.CENTER_HORIZONTAL, 0, 0);
			} else {
				ByAlert.alert("请先选择城市地区");
			}
			break;
		case R.id.jvjia_repair_leixing:// 选择报修类型
			laiYuanPopup(v);

			break;
		case R.id.jvjia_repair_chengdu:// 报修程度
			chengDuPopup(v);
			break;
		case R.id.jvjia_repair_ok:// 完成
			repairPersenter02 = new RepairPersenter(this);
			uid = (String) SPUtils.get(this, null, SPContants.USER_ID, "");
			if (sb != null) {
				if (sb.toString().length() > 0) {
					str = sb.toString().substring(0, sb.length() - 1);
				}
			}
			name = et_name.getText().toString();
			if (name.equals("")) {
				ByAlert.alert("请输入姓名");
				return;
			}
			phone = et_phone.getText().toString();
			if (phone.equals("")) {
				ByAlert.alert("请输入手机号");
				return;
			}
			if (repair_id == null) {
				ByAlert.alert("请选择维修类型");
				return;
			}
			if (xiaoquCode == null) {
				ByAlert.alert("请选择小区");
				return;
			}
			if (addr == null) {
				ByAlert.alert("请选择详细地址");
				return;
			}
			uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
			sb = new StringBuffer();
			List<File> files = new ArrayList<File>();
			for (int i = 0; i < listImg.size(); i++) {
				files.add(new File(listImg.get(i)));
			}
			
			int size = files.size();
			if (size > 0) {
				
				Map<String, String> params = new HashMap<String, String>();
				params.put("uid", uid);
				params.put("type", "repair");

				MultipartRequest multipartRequest = new MultipartRequest(
						NetPublicConstant.URL
								+ "/file/upload?client_id=by565fa4facdb191",
						new Listener<String>() {

							@Override
							public void onResponse(String arg0) {
								// TODO Auto-generated method stub
								String code = "";
								String result = "";
								try {
									JSONObject jsonObject = new JSONObject(arg0);
									code = jsonObject.getString("code");
									result = jsonObject.getString("data");
									if (code.equals("-1")) {
										ByAlert.alert(result);
									} else {
										Gson gson = new Gson();
										Type type = new TypeToken<AvatarBeans>() {
										}.getType();
										Log.v("msg", result + "我是正确的");
										AvatarBeans avatarBeans = gson
												.fromJson(arg0, type);
										for (AvatarDataBeans bean : avatarBeans
												.getData()) {
											sb.append(bean.getId() + ",");
										}
										repairPersenter02.shenQingWeiXiu(uid
												+ "", str == null ? "" : str,
												name, phone, repair_id,
												repair_status + "",
												et_xiangqing.getText()
														.toString(), addr,
												xiaoquCode, "1", "");
									}
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}, new ErrorListener() {

							@Override
							public void onErrorResponse(VolleyError arg0) {
								// TODO Auto-generated method stub
								ByAlert.alert(arg0);
							}
						}, "image[]", files, params);
				MyApplcation.addRequest(multipartRequest);
			} else {
				showProgressDialog("申请中,请稍后", true);
				repairPersenter02.shenQingWeiXiu(uid + "", str == null ? ""
						: str, name, phone, repair_id, repair_status + "",
						et_xiangqing.getText().toString(), addr, xiaoquCode,
						1 + "", "");
			}

			break;
		case R.id.huxing_ok:
			QuYuBean quYuBean = null;
			Children children = null;
			try {
				quYuBean = nume01.getPosition(chengshiFather.getCurrentItem());
				children = cityChildAdpter.getChildPoisition(chengshiChild
						.getCurrentItem());
			} catch (Exception e) {
				// TODO: handle exception
			}

			quCode = (children == null ? quYuBean.getCode() : children
					.getCode());
			hourse02 = new HousePresenter(ActivityJvJiaRepair.this);
			hourse02.getQuyuLieBiao02(quCode);

			text_shiqu
					.setText(quYuBean.getName() + "  " + children == null ? ""
							: children.getName());
			chengshiPop.dismiss();
			break;

		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		return R.layout.activity_jvjia_repair;
	}

	@Override
	protected void onInitController() {
		repairType = getIntent().getIntExtra("type", 1);
		noScrollgridview = (XGridView) findViewById(R.id.noScrollgridview);
		noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
		adapter = new GridAdapter(this);
		noScrollgridview.setAdapter(adapter);

		noScrollgridview.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (arg2 == listImg.size()) {
					new PopupWindows(ActivityJvJiaRepair.this, noScrollgridview);
				} else {
					Intent intent = new Intent(ActivityJvJiaRepair.this,
							CopyOfPhotoActivity.class);
					intent.putExtra("ID", arg2);
					intent.putExtra("type", 5);
					startActivity(intent);
				}
			}
		});
	}

	@Override
	protected void onInit() {
		add_shap_title_tv.setText(getIntent().getStringExtra("title"));
		
		hourse = new HousePresenter(this);
		hourse.getQuyuLieBiao("");
		repairPersenter = new RepairPersenter(this);
		repairPersenter.weiXiuXinXi("2");//查看维修信息
		uid = (String) SPUtils.get(this, null, SPContants.USER_ID, "");
		repairPersenter.getWeiXiuDiZhi(uid);//获取维修地址
	}

	@Override
	protected void onReadIntent(Bundle bundle) {

	}

	/**
	 *详细地址
	 */
	private void dizhiPopup(View v) {
		realLayout = (RelativeLayout) LayoutInflater.from(this).inflate(
				R.layout.qiuzu_chengqu, null);
		cheng_listView = (ListView) realLayout
				.findViewById(R.id.cheng_listView);
		if(dizhiBean!=null){
			if (dizhiBean.size() > 0) {
				weiXiuDiZhiAdapter = new WeiXiuDiZhiAdapter(this, dizhiBean);
				cheng_listView.setAdapter(weiXiuDiZhiAdapter);
			}
		}

		mPopWin = new PopupWindow(realLayout,
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT, true);
		mPopWin.setBackgroundDrawable(new BitmapDrawable());
		mPopWin.showAsDropDown(shaixuan_main, 5, 1);
		mPopWin.update();

		cheng_listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				text_dizhi.setText(dizhiBean.get(position).getAddress_detail());
				addr = dizhiBean.get(position).getAddress_detail();
				mPopWin.dismiss();
			}
		});

	}

	
	/**
	 * 报修类型
	 */
	private void laiYuanPopup(View v) {
		realLayout = (RelativeLayout) LayoutInflater.from(this).inflate(
				R.layout.qiuzu_chengqu, null);
		cheng_listView = (ListView) realLayout
				.findViewById(R.id.cheng_listView);
		if (household.size() > 0) {
			leiXingAdapter = new LeiXingAdapter02(this, household);
			cheng_listView.setAdapter(leiXingAdapter);
		}

		mPopWin = new PopupWindow(realLayout,
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT, true);
		mPopWin.setBackgroundDrawable(new BitmapDrawable());
		mPopWin.showAsDropDown(shaixuan_main, 5, 1);
		mPopWin.update();

		cheng_listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				text_leixing.setText(household.get(position).getName());
				repair_id = household.get(position).getId();
				mPopWin.dismiss();
			}
		});

	}

	/**
	 * 报修程度
	 */
	private void chengDuPopup(View v) {
		realLayout = (RelativeLayout) LayoutInflater.from(this).inflate(
				R.layout.qiuzu_chengqu, null);
		cheng_listView = (ListView) realLayout
				.findViewById(R.id.cheng_listView);

		list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map01 = new HashMap<String, Object>();
		map01.put("aaa", "检测");
		Map<String, Object> map02 = new HashMap<String, Object>();
		map02.put("aaa", "检修");
		Map<String, Object> map03 = new HashMap<String, Object>();
		map03.put("aaa", "小修");
		Map<String, Object> map04 = new HashMap<String, Object>();
		map04.put("aaa", "大修");

		list.add(map01);
		list.add(map02);
		list.add(map03);
		list.add(map04);

		SimpleAdapter adapter = new SimpleAdapter(this, list,
				R.layout.item_choose_area, new String[] { "aaa" },
				new int[] { R.id.name });

		cheng_listView.setAdapter(adapter);

		mPopWin = new PopupWindow(realLayout,
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT, true);
		mPopWin.setBackgroundDrawable(new BitmapDrawable());
		mPopWin.showAsDropDown(shaixuan_main, 5, 1);
		mPopWin.update();

		cheng_listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				text_chengdu.setText(list.get(position).get("aaa").toString());
				repair_status = position + 1;

				mPopWin.dismiss();
			}
		});

	}

	/**
	 * 选择市区
	 */
	private void chengShi() {
		chengshiPop = new ChengShiPopupWindow(this, this, "市区选择");
		chengshiFather = (WheelView) chengshiPop.getContentView().findViewById(
				R.id.huxing_01);
		chengshiFather.setBackgroundResource(R.drawable.white);
		System.out.println(chengShiBean.size() + "城市条目");
		nume01 = new CityWheelAdapter(MyApplcation.ctx, 1, chengShiBean.size());
		nume01.setLabel("室");
		nume01.setDatas(chengShiBean);
		// NumericWheelAdapter nume02 = new
		// NumericWheelAdapter(MyApplcation.ctx,
		// 1, chengShiBean.size());
		chengshiFather.setViewAdapter(nume01);
		chengshiFather.setCyclic(false);// 是否可循环滑动
		chengshiFather.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				setCityChildenData(wheel.getCurrentItem());
				// wheel.getCurrentItem();
			}
		});
		// 设置点击其他地方就消失
		chengshiPop.setOutsideTouchable(true);
		chengshiPop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
		chengshiPop
				.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

		chengshiChild = (WheelView) chengshiPop.getContentView().findViewById(
				R.id.huxing_02);
		chengshiChild.setBackgroundResource(R.drawable.white);
		setCityChildenData(0);
	}

	/**
	 * 选择小区
	 */
	private void xiaoqu() {
		xiaoquPop = new XiaoQuPopupWindow(this, xiaoquClickLisenter, "小区选择");
		xiaoquFather = (WheelView) xiaoquPop.getContentView().findViewById(
				R.id.huxing_01);
		xiaoquFather.setBackgroundResource(R.drawable.white);
		System.out.println(quBean.size() + "小区父类条目");
		xiaoquFatherAdapter = new XiaoQuFatherWheelAdapter(MyApplcation.ctx, 1,
				quBean.size());
		xiaoquFatherAdapter.setDatas(quBean);
		xiaoquFather.setViewAdapter(xiaoquFatherAdapter);
		// xiaoquFather.setVisibleItems(3);
		xiaoquFather.setCyclic(false);// 是否可循环滑动
		xiaoquFather.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				setXiaoQuChildenData(wheel.getCurrentItem());
				// wheel.getCurrentItem();
			}
		});

		// 设置点击其他地方就消失
		xiaoquPop.setOutsideTouchable(true);
		xiaoquPop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
		xiaoquPop
				.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		xiaoquChild = (WheelView) xiaoquPop.getContentView().findViewById(
				R.id.huxing_02);
		xiaoquChild.setBackgroundResource(R.drawable.white);
		setXiaoQuChildenData(0);
	}

	/**
	 * 小区
	 * 
	 * @param index
	 */
	void setXiaoQuChildenData(int index) {
		if (quBean != null) {
			if (quBean.size() > 0) {
				if (quBean.get(index).getChildren().size() > 0) {
					xiaoquChildAdapter = new XiaoQuChildWheelAdapter(
							MyApplcation.ctx, 1, quBean.get(index)
									.getChildren().size());
					// nume03.setLabel("厅");
					xiaoquChildAdapter
							.setDatas(quBean.get(index).getChildren());
					xiaoquChild.setViewAdapter(xiaoquChildAdapter);
					xiaoquChild.setCyclic(false);// 是否可循环滑动
					xiaoquChild
							.addScrollingListener(new OnWheelScrollListener() {

								@Override
								public void onScrollingStarted(WheelView wheel) {
									// TODO Auto-generated method stub

								}

								@Override
								public void onScrollingFinished(WheelView wheel) {
									// TODO Auto-generated method stub

								}
							});
				} else {
					xiaoquChildAdapter = new XiaoQuChildWheelAdapter(
							MyApplcation.ctx, 0, 0);
					xiaoquChildAdapter.notifyDataSetChanged();
					xiaoquChild.setViewAdapter(xiaoquChildAdapter);
				}
			} else {
				xiaoquChildAdapter = new XiaoQuChildWheelAdapter(
						MyApplcation.ctx, 0, 0);
				xiaoquChildAdapter.notifyDataSetChanged();
				xiaoquChild.setViewAdapter(xiaoquChildAdapter);
			}
		} else {
			xiaoquChildAdapter.notifyDataSetChanged();
			xiaoquChild.setViewAdapter(xiaoquChildAdapter);
		}
	}

	/**
	 * 小区弹出框的点击
	 */
	OnClickListener xiaoquClickLisenter = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.huxing_cancel:
				break;
			case R.id.huxing_ok:
				QuBean xiaoquFatherBean = xiaoquFatherAdapter
						.getPosition(xiaoquFather.getCurrentItem());
				com.itboye.ihomebank.adapter.QuBean.Children children = null;
				try {
					children = xiaoquChildAdapter.getPosition(xiaoquChild
							.getCurrentItem());
				} catch (Exception e) {
					// TODO: handle exception
				}
				text_xiaoqu.setText(xiaoquFatherBean.getName() + "  "
						+ (children == null ? "" : children.getName()));
				xiaoquCode = (children == null ? xiaoquFatherBean.getCode()
						: children.getCode());
				break;
			default:
				break;
			}

			xiaoquPop.dismiss();
		}
	};

	/**
	 * 市区
	 * 
	 * @param index
	 */
	void setCityChildenData(int index) {
		if (chengShiBean != null) {
			if (chengShiBean.size() > 0) {
				if (chengShiBean.get(index).getChildren().size() > 0) {
					cityChildAdpter = new CityChildrenWheelAdapter(
							MyApplcation.ctx, 1, chengShiBean.get(index)
									.getChildren().size());
					// nume03.setLabel("厅");
					cityChildAdpter.setDatas(chengShiBean.get(index)
							.getChildren());
					chengshiChild.setViewAdapter(cityChildAdpter);
					chengshiChild.setCyclic(false);// 是否可循环滑动
					chengshiChild
							.addScrollingListener(new OnWheelScrollListener() {

								@Override
								public void onScrollingStarted(WheelView wheel) {
									// TODO Auto-generated method stub

								}

								@Override
								public void onScrollingFinished(WheelView wheel) {
									// TODO Auto-generated method stub

								}
							});
				}
			}
		}
	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = handlerError(data);
		// ByAlert.alert(entity.getData());
		if (entity != null) {
			if (!entity.getCode().equals(0)) {

				if (entity.getEventType() == HousePresenter.quyuLieBiao_success) {
					chengShiBean = (List<QuYuBean>) entity.getData();

					chengShiChildrenbean = new ArrayList<QuYuBean.Children>();

					for (int i = 0; i < chengShiBean.size(); i++) {
						chengShiChildrenbean.addAll(chengShiBean.get(i)
								.getChildren());// 得到市下面的区
					}
				}
				if (entity.getEventType() == HousePresenter.quyuLieBiao_fail) {
					ByAlert.alert(chengShiChildrenbean.toString());
				}
				if (entity.getEventType() == HousePresenter.quyuLieBiao02_success) {
					quBean = (List<QuBean>) entity.getData();

					quBeanChildren = new ArrayList<QuBean.Children>();

					for (int i = 0; i < quBean.size(); i++) {
						quBeanChildren.addAll(quBean.get(i).getChildren());// 得到区域下面的小区
					}
				}
				if (entity.getEventType() == HousePresenter.quyuLieBiao02_fail) {
					ByAlert.alert(entity.getData());
				}

				if (entity.getEventType() == RepairPersenter.weixiuXinxi_success) {
					WeixiuXinxiBean bean = (WeixiuXinxiBean) entity.getData();
					if (bean != null) {
						household.addAll(bean.getFurniture());
					}

				}
				if (entity.getEventType() == RepairPersenter.weixiuXinxi_fail) {
					ByAlert.alert(entity.getData());

				}

				if (entity.getEventType() == RepairPersenter.shenQingWeiXiu_success) {
					ByAlert.alert(entity.getData());
					finish();
				}
				if (entity.getEventType() == RepairPersenter.shenQingWeiXiu_fail) {
					ByAlert.alert(entity.getData());
				}
				//维修地址
				if (entity.getEventType() == RepairPersenter.dizhi_success) {
					dizhiBean=(List<WeiXiuDiZhiBean>) entity.getData();
					
				}
				if (entity.getEventType() == RepairPersenter.dizhi_fail) {
					ByAlert.alert(entity.getData());
				}
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
		}
	}

	protected void onRestart() {
		adapter = new GridAdapter(this);
		noScrollgridview.setAdapter(adapter);
		super.onRestart();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		listImg.clear();
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case TAKE_PICTURE:
			if (listImg.size() < 9 && resultCode == -1) {
				listImg.add(path);
			}
			break;
		}
	}

	private static final int TAKE_PICTURE = 0x000000;
	private String path = "";

	public void photo() {
		Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		File file = new File(Environment.getExternalStorageDirectory()
				+ "/myimage/", String.valueOf(System.currentTimeMillis())
				+ ".jpg");
		path = file.getPath();
		Uri imageUri = Uri.fromFile(file);
		openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
		startActivityForResult(openCameraIntent, TAKE_PICTURE);
	}

	public class GridAdapter extends BaseAdapter {
		private LayoutInflater inflater; // 视图容器
		private int selectedPosition = -1;// 选中的位置
		private boolean shape;

		public boolean isShape() {
			return shape;
		}

		public void setShape(boolean shape) {
			this.shape = shape;
		}

		public GridAdapter(Context context) {
			inflater = LayoutInflater.from(context);
		}

		public int getCount() {
			return (listImg.size() + 1);
		}

		public Object getItem(int arg0) {

			return null;
		}

		public long getItemId(int arg0) {

			return 0;
		}

		public void setSelectedPosition(int position) {
			selectedPosition = position;
		}

		public int getSelectedPosition() {
			return selectedPosition;
		}

		/**
		 * ListView Item设置
		 */
		public View getView(int position, View convertView, ViewGroup parent) {
			final int coord = position;
			ViewHolder holder = null;
			if (convertView == null) {

				convertView = inflater.inflate(R.layout.item_published_grida,
						parent, false);
				holder = new ViewHolder();
				holder.image = (ImageView) convertView
						.findViewById(R.id.item_grida_image);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			if (position == listImg.size()) {
				holder.image.setImageBitmap(BitmapFactory.decodeResource(
						getResources(), R.drawable.icon_addpic_unfocused));
				if (position == 9) {
					holder.image.setVisibility(View.GONE);
				}
			} else {
				XImageLoader.load("file://" + listImg.get(position),
						holder.image);
			}

			return convertView;
		}

		public class ViewHolder {
			public ImageView image;
		}
	}

	public class PopupWindows extends PopupWindow {

		public PopupWindows(Context mContext, View parent) {

			View view = View
					.inflate(mContext, R.layout.item_popupwindows, null);
			view.startAnimation(AnimationUtils.loadAnimation(mContext,
					R.anim.fade_ins));
			LinearLayout ll_popup = (LinearLayout) view
					.findViewById(R.id.ll_popup);
			ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,
					R.anim.push_bottom_in_2));

			setWidth(LayoutParams.FILL_PARENT);
			setHeight(LayoutParams.FILL_PARENT);
			setBackgroundDrawable(new BitmapDrawable());
			setFocusable(true);
			setOutsideTouchable(true);
			setContentView(view);
			showAtLocation(parent, Gravity.BOTTOM, 0, 0);
			update();

			Button bt1 = (Button) view
					.findViewById(R.id.item_popupwindows_camera);
			Button bt2 = (Button) view
					.findViewById(R.id.item_popupwindows_Photo);
			Button bt3 = (Button) view
					.findViewById(R.id.item_popupwindows_cancel);
			bt1.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					photo();
					dismiss();
				}
			});
			bt2.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					Intent intent = new Intent(ActivityJvJiaRepair.this,
							CopyOfTestPicActivity.class);
					intent.putExtra("type", 5);
					intent.putExtra("max", 9 - listImg.size());
					startActivity(intent);

					dismiss();
				}
			});
			bt3.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					dismiss();
				}
			});

		}
	}

	@Override
	public void OnSuccess(String resultData) {
		sb.append(resultData + ",");
		ByAlert.alert(resultData);

	}

	@Override
	public void OnError(String resultData) {
		ByAlert.alert(resultData);

	}
}
